<%@ page import="cn.kgc.javaweb.entity.Student" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.HashMap" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>el表达式的基本使用</title>
</head>
<body>
<%--
    El表达式的作用： 从四大域对象中取值
--%>
<%--El表达式支持运算--%>
<p>1+2=${1+2}</p>
<p>1>2=${1 > 2}</p>
<p>true&&false=${true&&false}</p>

<%--El表达式取值
    如果没有指定域对象 那么按照从小到大的范围依次取值  pageScope requestScope  sessionScope  applicationScope
--%>

<%
    // jsp的四大域对象
    pageContext.setAttribute("username", "pageContext");
    request.setAttribute("username", "request");
    session.setAttribute("username", "session");
    application.setAttribute("username", "application");


    //域对象中存储对象类型的值
    Student student = new Student();
    student.setId(1);
    student.setSex("男");
    student.setAge(20);
    student.setStuName("tom");
    pageContext.setAttribute("student", student);

    String[] str = {"tom","jack","lucy"};
    pageContext.setAttribute("array", str);

    List<String> list = Arrays.asList("tom", "jack", "lucy");
    pageContext.setAttribute("list",list);

    HashMap<String, Object> map = new HashMap<>();
    map.put("username", "admin");
    map.put("password", "root");

    pageContext.setAttribute("map", map);
%>
<%--指定作用域取值--%>
<p>username:${pageScope.username}</p>
<p>username:${applicationScope.username}</p>

<%--从域对象中取出student对象--%>
<p>id=${student.id}</p>
<p>name=${student.stuName}</p>
<p>sex=${student.sex}</p>
<p>age=${student.age}</p>

<%--从域对象中取出数组中的值--%>
<p>array[0] = ${array[0]}</p>
<p>array[1] = ${array[1]}</p>
<p>array[2] = ${array[2]}</p>

<%--从域对象中取出集合中的值--%>
<p>list[0] = ${list[0]}</p>
<p>list[1] = ${list[1]}</p>
<p>list[2] = ${list[2]}</p>

<%--从域对象中取出map集合中的值--%>
<p>map[username] = ${map["username"]}</p>
<p>list[password] = ${map["password"]}</p>


</body>
</html>
